import type { Connection } from '../types';
import ApiConfig from './config'

// 基础URL（已通过vite.config.ts配置代理）
const BASE_URL = '/api/connections';

// 获取所有连接
export const getAllConnections = async (tabId: string) => {
  return ApiConfig.get<Connection[]>(`${BASE_URL}?tabId=${tabId}`)
}

export const createConnection = async (data: Omit<Connection, 'id'>) => {
  return ApiConfig.post<Omit<Connection, 'id'>, Connection>(BASE_URL, data)
}

export const deleteConnection = async (id: string) => {
  return ApiConfig.delete<void, void>(`${BASE_URL}/${id}`)
}

export const deleteConnections = async (ids: string[]) => {
  return ApiConfig.delete<{ids: string[]}, void>(BASE_URL, {ids})
}